#include<iostream>
#include<vector>
using namespace std;

void test01() {
    int num = 0;
    int *p = NULL;
    vector<int> v;
    for (float i = 0; i < 100000; i++) {
        v.push_back(i);
        if (p != &v[0]) {
            p = &v[0];
            num++; //此时更新了18次首地址，相当于重分配了18次，再试试引用reserve预留地址呢?
        }
    }
    cout << num << endl;
}

void test02() {
    int num = 0;
    int *p = NULL;
    vector<int> v;
    v.reserve(100000);
    for (float i = 0; i < 100000; i++) {
        v.push_back(i);
        if (p != &v[0]) {
            p = &v[0];
            num++; //此时更新了1次首地址,因为预留了内存等待分配
        }
    }
    cout << num << endl;
}

int main() {
    test01();
    test02();
    return 0;
}